<?php

namespace App\Http\Controllers\Test;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;

class TestController extends Controller
{
    //闭包事务
    public function shiwu(){
        DB::transaction(function(){
            $res1 = DB::table("test1")->insert(['name'=>"name1"]);
            $res2 = DB::table("test2")->insert(['name'=>"name2"]);
            if($res1 && $res2){
                DB::commit();
                echo "执行成功";
            }else{
                DB::rollback();
                echo "执行失败";
            }
        });
    }

    //测试
    public function index(){
        echo "更改内容";
    }
}
